<?php

use Phalcon\Mvc\Controller;

class ControllerBase extends Controller
{

    public static  function success($url,$msg="操作成功",$exit=true,$alert=true){
        if($alert){
            echo "<script>alert('".$msg."');</script>";;
        }
        if($url=="reload"){
            //echo "<script>alert('".$msg."');parent.trigger_click(\"btnquery\");</script>";;
            echo "<script>parent.document.getElementById(\"formquery\").submit();;</script>";;
        }elseif($url=="reloadself"){
            //echo "<script>alert('".$msg."');</script>";;
        }
        else{
            echo "<script>location.href='".$url."';</script>";;
        }
        if($exit){
            exit();
        }

    }
    public static  function error($msg="操作失败"){
        echo "<script>alert('".$msg."');history.go(-1);</script>";;
        exit();
    }
    /*public function error($message = '',$url='')
    {

        $this->dispatcher->forward(
            [
                "controller" => "message",
                "action"     => "error",
                'params'     => [
                    'message' => $message,
                    'url'      => $url,
                ]

            ]
        );
    }
    public function success($message, $url=''){
        $this->dispatcher->forward(
            [
                "controller" => "message",
                "action"     => "success",
                'params'     => [
                    'message' => $message,
                    'url'      => $url,
                ]

            ]
        );
    }*/


    public function login($message = '')
    {

        $this->dispatcher->forward(
            [
                "controller" => "message",
                "action"     => "login",
                'params'     => [
                    'message' => $message,
                ]

            ]
        );
    }


    public function getUserID(){
        if($this->session->get("users")){
            return $this->session->get('users')['user_id'];
        }
        return 0;
    }
}
